<?php 
   require_once('config.php');
   $action = getValue('action','str','POST','');
   $album_name = getValue('album_name','str','POST');
   $album_id   = getValue('album_id','int','POST');
   $cat_id     = getValue('cat_id','int','POST');
   $link_profile = getValue('link_profile','str','POST');
   if($action != ''){
      $content = getValue('content','str','POST','');
      $content = str_replace("\\","",$content);      
      echo $content;
      //echo '<script type="text/javascript">submitContent("'.$album_name.'","'.$link_profile.'")</script>';
   }   
?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Lấy ảnh từ facebook</title>
   <?=$css_global?>
   <style>
      figure img{
         float:left;
         max-width: 80px;
         margin-right: 10px;
      }
   </style>
   <?=$js_global?>
</head>
<div class="row-fluid">
   <div class="head">
      <div class="isw-grid"></div>
      <h1>Lấy ảnh từ facebook</h1>      
      <div class="reload_tab" title="Reload"></div>                         
      <div class="clear"></div>
   </div>
   <div class="block-fluid">
      <form class="form-horizontal" name="add" action="" method="POST" enctype="multipart/form-data"  onsubmit="">
         <input type="hidden" name="action" value="submit" />
         <fieldset>
            <div class="control-group">
               <label class="control-label" for="input01">Tạo mới album</label>
               <div class="controls">
                  <input type="text" name="album_name" class="span5" id="album_name" placeholder="Tạo mới album" />
               </div>
            </div>
            <div class="control-group">
               <label class="control-label" for="input01">Thể loại</label>
               <div class="controls">
                  <select id="cat_id" name="cat_id">
                     <?foreach($array_cate as $key=>$value){?>
                        <option value="<?=$key?>"><?=$value?></option>
                     <?}?>
                  </select>
               </div>
            </div>
            <div class="control-group">
               <label class="control-label" for="input01">Chọn album</label>
               <div class="controls">
                  <input type="text" name="album_id" class="span5" id="album_id" placeholder="Gõ vào một tên album" />
               </div>
            </div>
            <div class="control-group">
               <label class="control-label" for="input01">Link profile</label>
               <div class="controls">
                  <input type="text" name="link_profile" class="span6" id="link_profile" placeholder="Link profile facebook" />
               </div>
            </div>
            <div class="control-group">
               <label class="control-label" for="input01">HTML</label>
               <div class="controls">
                  <textarea name="content" style="width: 100%;" rows="10"></textarea>
               </div>
            </div>
            <div class="form-actions">
					<button type="submit" class="btn btn-info">Lấy ảnh</button>
					<button type="reset"  class="btn btn-warning">Làm lại</button>
				</div>
         </fieldset>
      </form>
   </div> 
</div>
<script>
   $(function(){
      
         // Suggest name album
         $("#album_id").tokenInput("ajax_token_input_album.php", {
            theme: "facebook",
            preventDuplicates: true,
         });
         
         //Submit json to INSERT database
         var arrayPic = [];
         var album = '<?=$album_name?>';
         var profile = '<?=$link_profile?>';
         var alb_id = '<?=$album_id?>';
         var cat_id = '<?=$cat_id?>'
         $('figure img').each(function(){
            linkPicture = $(this).attr('src');
            arrayPic.push(linkPicture);
         });
         var jsonString = JSON.stringify(arrayPic);
         if(jsonString.length > 2){
            $.ajax({
               url:'ajax_insert_images.php',
               type:'POST',
               data:{'data':arrayPic,'album':album,'alb_id':alb_id,'cat_id':cat_id,'profile':profile},
               dataType:'json',
            });
         }
         
   });
</script>
</html>